package com.gitee.hljdrl.dialog.util;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Looper;
import android.util.TypedValue;

public class UIUtil {


    public static boolean isUIThread() {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            // UI线程
            return true;
        }
        return false;
    }

    public static int dp2px(Context context, float value) {
        return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, context.getResources().getDisplayMetrics()) + 0.5f);
    }

    public static int screenHeight() {
        return Resources.getSystem().getDisplayMetrics().heightPixels;
    }

    private static long lastClickTime;
    private final static long TIME = 800;

    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < TIME) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    public static boolean isFastDoubleClick(long minTime ) {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < TIME) {
            return true;
        }
        lastClickTime = time;
        return false;
    }


    public static void dismissDialog(Dialog dialog) {
        if (dialog != null && dialog.isShowing()) {
            try {
                dialog.dismiss();
            } catch (Exception ex) {
            }
        }
    }

    public static boolean isShowing(Dialog dialog) {
        if (dialog != null && dialog.isShowing()) {
            return true;
        }
        return false;
    }
}
